package com.ct.bigscreen.controller;

import com.ct.bigscreen.bean.Result;
import com.ct.bigscreen.mapper.ViewMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 用来接收前端数据请求的controller
 */
//=@Controller+@ResponseBody表示该类是springboot的一个controller，且返回的数据为JSON格式
@CrossOrigin(origins = "*", maxAge = 3600)  //解决前后端分离的跨域访问问题
@RestController   //=@Controller+@ResponseBody表示该类是springboot的一个controller，且返回的数据为JSON格式
@RequestMapping("/BigScreen")
public class ViewController {

    @Autowired
    private ViewMapper viewMapper;

    @RequestMapping("/getRegionalData")
    public Result getRegionalData() {
        System.out.println("接收前端发起的JSON数据请求，后续需要查询mysql将数据返回");
        List<Map<String, Objects>> data = viewMapper.getRegionalData();
        Result result = Result.success(data);
        return result;

    }

    @RequestMapping("/getTrendData")
    public Result getTrendData() {
        System.out.println("收到前端的薪资信息JSON数据请求,查取后端MySQL数据");
        List<Map<String, Objects>> data = viewMapper.getTrendData();
        Result result = Result.success(data);
        System.out.println(result);
        return result;
    }


    @RequestMapping("/getPopularData")
    public Result getPopularData(){
        System.out.println("收到前端的行业JSON信息请求，查取后端MySQL数据");
        List<Map<String, Objects>> data = viewMapper.getPopularData();
        Result result = Result.success(data);
        return result;
    }

}
